<?php
/*
 * 手机客户端店铺-商品留言列表接口
 * 2014-02-26
 * 2014-05-08 (已查) 
 */
include "inc/public_header.php";
include "func/user.php";				//用户信息处理函数

//头像根路径
$LOGO_BASE_PATH = "http://www.chinalaohu.com/modules/miniature.php?w=150&h=150&p=/uploads/zjl_ilogo/";

//默认头像
$LOGO_DEFAULT_PATH = "http://www.chinalaohu.com/images/zjl/logo.png";

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
$uid = $uInfoArr["uid"]; //用户信息主键

$reJson = array(); //构建返回值

$product_id 	= $_REQUEST["goodsId"];	//商品id
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数

if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 20; //默认每页20条
}

$reJson["success"] = "1";

//1 店主 0 用户或是游客
$sql = "select uid from shop_product where product_id = '".$product_id."'";
$db1->query($sql);
$db1->next_record();
if ($uid == $db1->f("uid")){
$reJson["shopkeeper"] = "1";
}else{
$reJson["shopkeeper"] = "0";
}

//留言条数
$sql = "select 
			count(id) as ct 
		from 
			shop_product_liuyan 
		where 
			pid = '".$product_id."'
		";
$db1->query($sql);
$db1->next_record();
$reJson["count"] = $db1->f("ct");

//商品留言列表
$sql = "SELECT a.id,c.ilogo_path,b.mobile,c.nickname,a.ctime,a.msg,a.type FROM shop_product_liuyan a left JOIN user_base b on a.uid=b.uid left JOIN new_weituo_person c on a.uid=c.uid where a.pid='".$product_id."' ORDER BY a.lid,a.id"; 
$db->query($sql);
$msgArr = array();
while($db->next_record()){
	$id	   		= $db->f("id");
	$ilogo_path	= $db->f("ilogo_path");
	if($ilogo_path==null){
		//默认头像
		$ilogo_path = $LOGO_DEFAULT_PATH;
	}else{
		$ilogo_path = $LOGO_BASE_PATH.$ilogo_path;
	}
	if ($db->f("nickname")){
	$nickname	= $db->f("nickname");
	}elseif ($db->f("mobile")){
	$nickname 	= $db->f("mobile");
	}else{
	$nickname = "游客";
	}
	$ctime	   	= $db->f("ctime");
	$msg	   	= $db->f("msg");
	$type	   	= $db->f("type");
	$msgArr[] = array(
		"msgId"=>$id						//消息id
		,"userIcon"=>$ilogo_path			//用户头像地址
		,"name"=>$nickname					//用户名称
		,"time"=>$ctime						//消息发出时间
		,"content"=>$msg					//消息内容
		,"client"=>$type					// 1 用户留言 0 店主回复
	);
}			
//放入商品留言列表
$reJson["list"] = $msgArr;

echo json_encode($reJson);
?>
